home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1993 October: Windmill on DISC / ADC Developer CD (1993-10) (''Windmill On DISC'')_iso / Dev.CD Oct 93.iso / System Software / U.S. System Software / System 7 Pro™ Beta 11 / Development Tools / Sample Code / Messaging Service Access Module / Internet PMSAM / Internet PMSAM source / gatewayput.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-10  |  2.9 KB  |  109 lines  |  [TEXT/MPS ]

  1. /*-------------------------------------------------------------------
  2.  
  3. AOCE Post Office Protocol (POP) / Simple Mail Transfer Protocol (SMTP)
  4. Mail Service Access Module
  5.  
  6. written by Steve Falkenburg-- MacDTS
  7. ©1991-1993 Apple Computer, Inc.
  8.  
  9. --------------
  10. change history
  11. --------------
  12.  
  13. SJF        02/19/93    update for beta build    b1
  14. SJF        10/29/92    update to a11            a11
  15. SJF        06/08/92    update to a8            a8
  16. SJF        02/15/92    first working version    a4.5
  17. SJF        10/16/91    initial coding            a3
  18.  
  19. ---------------------------------------------------------------------*/
  20.  
  21. #ifndef __OCE__
  22. #include <OCE.h>
  23. #endif
  24.  
  25. #ifndef __OCEMAIL__
  26. #include <OCEMail.h>
  27. #endif
  28.  
  29. #include "const.h"
  30. #include "gwerrors.h"
  31. #include "mytypes.h"
  32. #include "globals.h"
  33. #include "utils.h"
  34. #include "gatewaystuff.h"
  35. #include "spoolfromexternal.h"
  36. #include "authstuff.h"
  37. #include "errorhandling.h"
  38.  
  39. #include "gatewayput.h"
  40.  
  41.  
  42. // PeriodicCheckPut
  43. //
  44. // when the toolbox thinks that it's time to check for mail, this function is called, in addition
  45. // to being called on startup of the gateway
  46. //
  47. OSErr PeriodicCheckPut(void)
  48. {
  49.     short slotIndex,arrIndex;
  50.     SlotSpec *slotSpec;
  51.     OSErr err = noErr;
  52.     unsigned long dateTime;
  53.     
  54.     TraceExecution("\pPeriodicCheckPut");
  55.  
  56.     GetDateTime(&dateTime);    
  57.  
  58.     for (slotIndex = arrIndex = 0; (err==noErr) && (slotIndex<gNumSlots); arrIndex++) {
  59.         if (gSlotDatabase[arrIndex].active && gSlotDatabase[arrIndex].enabled) {    // if the slot is in use, process it
  60.             slotIndex++;
  61.             slotSpec = &gSlotDatabase[arrIndex];
  62.             if (slotSpec->dirIdentity.valid) {
  63.                 EnterAuthCriticalSection();    // don't allow locking of local identity while we're here
  64.                 if (TimeToCheckPut(&slotSpec->stdInfo.sendReceiveTimer,slotSpec->lastCheckPut,dateTime)) {
  65.                     err = DoSlotPut(slotSpec);
  66.                     err = RetrySlotError(err,slotSpec,true);
  67.                     if (err==noErr)
  68.                         slotSpec->lastCheckPut = dateTime;
  69.                 }
  70.                 ExitAuthCriticalSection();
  71.             }
  72.         }
  73.     }
  74.     return err;
  75. }
  76.  
  77.  
  78. // TimeToCheckPut
  79. //
  80. // returns true if it's time to check for mail.  this function assumes the mailtimers are
  81. // in minutes, not seconds, since this seems to be what the toolbox is using for its scheduling
  82. // of eppcs.  note that the OCEMail.h header file specifies that these values are in seconds.
  83. //
  84. Boolean TimeToCheckPut(MailTimers *mailTimer,unsigned long lastCheck,unsigned long curTime)
  85. {
  86.     DateTimeRec dtRec;
  87.     unsigned long midnightSecs;    
  88.  
  89.     switch (mailTimer->receiveTimeKind) {
  90.         case kMailTimerOff:
  91.             return false;                    // never check if there is no interval
  92.             break;
  93.         case kMailTimerFrequency:            // check if past frequency+lastCheck
  94.             return ((lastCheck + (60*mailTimer->receive.frequency))<curTime);
  95.             break;
  96.         case kMailTimerTime:                // check at a specific time
  97.             if ((lastCheck + kOneDaySecs) > curTime)
  98.                 return false;
  99.             Secs2Date(curTime,&dtRec);    // get date of last midnight
  100.             dtRec.hour = 0;
  101.             dtRec.minute = 0;
  102.             dtRec.second = 0;
  103.             Date2Secs(&dtRec,&midnightSecs);
  104.             return ( (midnightSecs+(60*mailTimer->receive.connectTime)) > curTime );
  105.             break;
  106.     }
  107.     return false;        
  108. }
  109.